﻿using System;
using System.Web.Services;
using HelpdeskServices.CrmWebReference;

/// <summary>
/// Workflow method's
/// </summary>
public class WorkFlow
{
    /// <summary>
    /// Initializes a new instance of the <see cref="WorkFlow"/> class.
    /// </summary>
    public WorkFlow()
    {
    }

    /// <summary>
    /// Launches the work flow on a spesific object, and spesific workflow.
    /// no checks are done for validity of workflow or entityid
    /// </summary>
    /// <param name="EntityId">The entity id.</param>
    /// <param name="entityType">Type of the entity.</param>
    /// <param name="workFlowId">The work flow id.</param>
    public void LaunchWorkFlow(Guid EntityId, string entityType, Guid workFlowId)
    {
    }
    [WebMethod]
    public void LaunchWorkFlow(string EntityId, string entityType, string WorkFlowId)
    {
        ExecuteWFProcessRequest request = new ExecuteWFProcessRequest();
        request.ProcessId = new Guid(WorkFlowId);
        request.EntityMoniker = new Moniker();
        request.EntityMoniker.Name = entityType.ToString();
        request.EntityMoniker.Id = new Guid(EntityId);
        using (CrmService microsoftCrmWebService = Common.CrmWebServiceProxy())
        {
            if (microsoftCrmWebService != null)
            {
                ExecuteWFProcessResponse response = (ExecuteWFProcessResponse)microsoftCrmWebService.Execute(request);
            }
        }
    }
}